<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.sql.*, support.*, java.util.*"%>
    
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<link href="main.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
	<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
	<script type="text/javascript" src="application.js"></script>
	
	<title>Applications</title>
</head>
<body>
<h1>Applications</h1>
<%
	LinkedList<ApplicantName> applicants = null;
	int specialization_id;
	int major_id;
	DatabaseAccessObject dao = new DatabaseAccessObject();
	if(request.getParameter("specialization_id") != null){
		specialization_id  = Integer.valueOf((String)request.getParameter("specialization_id"));
		applicants = dao.getApplicantNameBySpecialization(specialization_id);
	}
	else if(request.getParameter("major_id") != null){
		major_id  = Integer.valueOf((String)request.getParameter("major_id"));
		applicants = dao.getApplicantNameByMajor(major_id);
		
	}
	else{
		applicants = dao.getAllApplicantName();
	}
	
	pageContext.setAttribute("applicants", applicants);
%>

<table class="applications">
	<tr>
		<th>No.</th>
		<th>Applicant ID</th>
		<th>Name</th>
		<th></th>
	</tr>
    <c:forEach items="${applicants}" var="applicant" varStatus="status">
   	<tr class="${status.index % 2 == 0 ? 'odd' : 'even'}">
   		<td class="number">${status.count}</td>
   		<td class="id">${applicant.id}</td>
   		<td class="applicant">${applicant.name}</td>
   		<td><button type="button" onClick="clickButton(${applicant.id}, this)" value="info_space_${status.count}">Show</button></td>
   	</tr>
   	<tr>
   		<td colspan="4" id="info_space_${status.count}" class="info_space"></td>
   	</tr>
    </c:forEach>
</table>

</body>
</html>